home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_10_12
/
1012076b
< prev
next >
Wrap
Text File
|
1992-10-11
|
682b
|
29 lines
/* strtokf.c: Collect tokens via a function */
#include <stdio.h>
#include <string.h>
static char *sp = NULL; /* Internal string position */
char *strtokf(char *s, int (*f)(char))
{
if (s != NULL)
sp = s; /* Remember string address */
if (sp == NULL)
return NULL; /* No string supplied */
/* Skip leading, unwanted characters */
while (*sp != '\0' && !f(*sp))
++sp;
s = sp; /* Token starts here */
/* Build token */
while (*sp != '\0' && f(*sp))
++sp;
if (*sp != '\0')
*sp++ = '\0'; /* Insert string terminator */
return strlen(s) ? s : NULL;
}